package com.atguigu.gulimall.product;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CreateThread03 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("main start...");
        FutureTask<Integer> futureTask = new FutureTask<>(new Callable01());
        new Thread(futureTask).start();
        // get方法会一直阻塞，直到call方法运行完毕
        Integer result = futureTask.get();
        System.out.println("main end..." + result);


    }

    public static class Callable01 implements Callable<Integer> {
        @Override
        public Integer call() throws Exception {
            System.out.println("当前线程：" + Thread.currentThread().getName());
            int i = 10 / 2;
            System.out.println("运行结果：" + i);
            return i;
        }
    }
}
